import {computed, onUnmounted, ref} from 'vue'
import dayjs from 'dayjs';
export function useCountDown(){
  let time=ref(0);
  let timer=null;
  let formatTime= computed(()=>{
    return dayjs.unix(time.value).format('mm分ss秒');
  })
  let start=(currentTime)=>{
    time.value=currentTime;
    timer= setInterval(()=>{
      time.value--;
    },1000)
  }
  onUnmounted(()=>{
    clearInterval(timer);
  })
  return {
    formatTime,
    start,
  }
}
